//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "math\fn_getRanPointCircle.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_center", "_radius", "_center_x", "_center_y", "_ret_val", "_co", "_angle", "_x1", "_y1", "_helper","_slope_dist"];
DEFAULT_PARAM(_center,0,[]);
DEFAULT_PARAM(_radius,1,100);
DEFAULT_PARAM(_min_dist,2,0);
DEFAULT_PARAM(_slope_dist,3,0);
if (_radius < _min_dist) then { _min_dist = 0; };

_center_x = _center select 0;_center_y = _center select 1;
_ret_val = [];_co = 0;
while {count _ret_val == 0 && _co < 100} do {
	_angle = floor (random 360);
	_randradius = _min_dist + random(_radius - _min_dist);
	_x1 = _center_x - (_randradius * sin _angle);
	_y1 = _center_y - (_randradius * cos _angle);
	if (!(surfaceiswater [_x1, _y1])) then {
		_helper = "Land_HelipadEmpty_F" createVehicleLocal [_x1,_y1,0];
		if (!(surfaceIsWater [getPosASL _helper select 0, getPosASL _helper select 1])) then {
			_slope = 0;
			// A negative slope dist will prevent a slope check, sometimes we don't need it.
			if (_slope_dist >= 0) then {
				_slope = [position _helper,_slope_dist] call FFUNC(getSlope);
			};
			if (_slope < 0.5) then {_ret_val = [getPosASL _helper select 0, getPosASL _helper select 1,0]};
		};
		deleteVehicle _helper;
	};
	if (count _ret_val == 0) then {_co = _co + 1};
};

TRACE_1("End",_ret_val);
TMFPROFILERSTOP;
_ret_val
